home *** CD-ROM | disk | FTP | other *** search
/ Light ROM 1 / LIGHT-ROM 1 (Amiga Library Services)(1994).iso / ffdisks / d909.lha / GoldED2 / Tools / HiSpeed / arexx / Appendix.rexx < prev    next >
OS/2 REXX Batch file  |  1993-08-28  |  3KB  |  148 lines

  1. /*
  2.     This script does look for words beginning with an '@'. These words
  3.     (and their locations/page numbers) are written to "T:KEY".
  4.     Afterwards, this file is transformed into a nice index & appended
  5.     to our list of jobs.
  6. */
  7.  
  8. shell
  9. options results
  10.  
  11. address HISPEED.1
  12.  
  13. SET REQUESTER ON
  14.  
  15. SET ASK "This script searches your document(s) for 'keywords'|(any word beginning with '@') and constructs a nice|appendix. Proceed ?"
  16.  
  17. if RESULT = 1 then do
  18.  
  19.   QUERY jobs
  20.  
  21.   if RESULT = 0 then
  22.     REQUESTFILE
  23.  
  24.   QUERY JOBS
  25.   jobcount = RESULT
  26.  
  27.   if jobcount ~= 0 then do
  28.  
  29.     /* extract keywords from text ... */
  30.  
  31.     SET KEYLIST 'T:KEY'           /* where to write the keyword list */
  32.     SET KEYCODE '@'               /* look for @ */
  33.     SET REQUESTER OFF             /* don't show scan-info */
  34.     SCAN                          /* create the keyword list */
  35.     SET REQUESTER ON              /* to show 'Done' requester ... */
  36.  
  37.     /* read list ... */
  38.  
  39.     R = open('KEY', 'T:KEY', 'READ')
  40.  
  41.     keys = 0                      /*  number of keywords */
  42.  
  43.     do until EOF('KEY')
  44.  
  45.       line = READLN('KEY')
  46.  
  47.       if ~EOF('KEY') then do
  48.  
  49.         parse var line job page name
  50.         keypage.keys = page
  51.         keyword.keys = name
  52.         keys = keys + 1
  53.  
  54.       end
  55.  
  56.     end
  57.  
  58.     R = close('KEY')
  59.  
  60.     if keys ~= 0 then              /* any keywords at all ? */
  61.  
  62.       do
  63.  
  64.         if keys > 1 then do
  65.  
  66.           /* sort alphabetically ? */
  67.  
  68.           SET ASK keys || " keywords detected. Do you want to have them sorted ?|Warning: can take _quite_ a while; this is ARexx, not|assembler ;-)"
  69.  
  70.           if RESULT = 1 then do
  71.  
  72.             do until ready = 1
  73.               ready = 1
  74.               do n = 0 to keys - 2
  75.                 m = n+1
  76.                 if upper(keyword.n) > upper(keyword.m) then do
  77.                   ready = 0
  78.                   swapword  = keyword.n
  79.                   swappage  = keypage.n
  80.                   keyword.n = keyword.m
  81.                   keypage.n = keypage.m
  82.                   keyword.m = swapword
  83.                   keypage.m = swappage
  84.                 end
  85.               end
  86.             end
  87.           end
  88.         end
  89.  
  90.         /* create final list */
  91.  
  92.         R = open('APDX', 'T:Appendix', 'WRITE')
  93.  
  94.         R = writeln('APDX', 'Appendix')
  95.         R = writeln('APDX', '--------')
  96.         R = writeln('APDX', '')
  97.  
  98.         last = ''
  99.  
  100.         do n = 0 to keys - 1
  101.           if upper(keyword.n) ~= last then
  102.             do
  103.               R = writeln('APDX', '')
  104.               R = writeln('APDX', '')
  105.               R = writech('APDX', left(keyword.n || copies('.', 65), 65) || ' ' || keypage.n)
  106.             end
  107.           else do
  108.               R = writeln('APDX', ',')
  109.               R = writech('APDX', copies(' ', 66) || keypage.n)
  110.           end
  111.           last = upper(keyword.n)
  112.         end
  113.  
  114.         R = writeln('APDX', '')
  115.         R = close('APDX')
  116.  
  117.         /* add new index file to list of jobs */
  118.  
  119.         shell
  120.         address HISPEED.1
  121.  
  122.         QUERY JOBS
  123.         last = RESULT-1
  124.  
  125.         do n = 0 to last
  126.           QUERY JOBNAME n
  127.           parse var RESULT path.n name.n rest
  128.         end
  129.  
  130.         if name.last = 'Appendix' then do
  131.           CLR
  132.           do n = 0 to last
  133.             if name.n ~= 'Appendix' then
  134.               SET FILE path.n || name.n
  135.           end
  136.         end
  137.  
  138.         SET FILE 'T:Appendix'
  139.         SET WARN 'ARexx message: MakeAppendix finished.'
  140.       end
  141.  
  142.     else
  143.  
  144.       SET WARN "No keywords found."
  145.   end
  146.  
  147. end
  148.